package com.zhiyizhen.callnumber.component;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import androidx.annotation.NonNull;

import com.zhiyizhen.callnumber.common.LogUtil;
import com.zhiyizhen.callnumber.common.ScreenUtil;
import com.zhiyizhen.callnumber.common.view.adapter.recyclerview.BaseAdapter;
import com.zhiyizhen.callnumber.common.view.adapter.recyclerview.BaseViewHolder;
import com.zhiyizhen.callnumber.component.bean.BoardListItem;
import com.zhiyizhen.callnumber.databinding.ItemBoardListBinding;

public class BoardListAdapter extends BaseAdapter<BoardListItem, BoardListAdapter.BoardViewHolder> {
    Context context;

    public BoardListAdapter(Context context) {
        super(context);
        this.context = context;
    }

    @NonNull
    @Override
    public BoardViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new BoardListAdapter.BoardViewHolder(this, ItemBoardListBinding.inflate(LayoutInflater.from(parent.getContext())));
    }

    static class BoardViewHolder extends BaseViewHolder<BoardListItem> {

        private final ItemBoardListBinding binding;

        public BoardViewHolder(BaseAdapter<BoardListItem, BoardListAdapter.BoardViewHolder> adapter, ItemBoardListBinding viewBinding) {
            super(adapter, viewBinding.getRoot());
            binding = viewBinding;
        }

        @Override
        public void bindData(BoardListItem data) {
            binding.roomNameTv.setText(data.getRoomName());
            binding.doctorNameTv.setText(data.getDoctorName());
            binding.visitingTv.setText(data.getVisiting());
            binding.waitingTv.setText(data.getWaiting());
            LogUtil.d("BoardListAdapter bindData w===" + ScreenUtil.screenWidth());
            LogUtil.d("BoardListAdapter bindData h===" + ScreenUtil.screenHeight());
            int width = Math.max(ScreenUtil.screenWidth(), ScreenUtil.screenHeight());
            binding.contentLayout.setLayoutParams(new LinearLayout.LayoutParams(width, ScreenUtil.dp2px(48)));
        }
    }
}
